import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import dateFormat from 'dateformat';
import { MypageService, PageBlock  } from '../../services/mypage.service';

@Component({
  selector: 'app-point',
  templateUrl: './point.component.html',
  styleUrls: ['./point.component.scss']
})
export class PointComponent implements OnInit {

  constructor(
    private activateRoute: ActivatedRoute,
    private mypageService: MypageService) { }

  title = 'Web';
  blocks: PageBlock[] = [];
  createdOn: string = "";
  updatedOn: string = "";
  taggs: string = "";

  ngOnInit(): void {
    let urlPar = this.activateRoute.snapshot.params;
    if(urlPar && urlPar.id) {
      this.mypageService.get(urlPar.id).subscribe(page=>{
        this.title = page.title;
        this.createdOn = dateFormat(new Date(page.createdOn), "yyyy-mm-dd HH:MM:ss");
        this.updatedOn = dateFormat(new Date(page.updatedOn), "yyyy-mm-dd HH:MM:ss");
        this.taggs = page.tags;
        this.blocks = page.blocks;        
        console.log(this.taggs);
      });
    }
  }

}
